# -*- coding: utf-8 -*-
from django.shortcuts import render

from .. import models


def project_list(request):  # 项目列表跳转
    return render(request, 'Page/Project_List.html')


def project_info(request):  # 项目信息跳转

    pj_name = request.POST.get('pj_name')
    if pj_name != None:
        global pjName
        pjName = pj_name
        return render(request, 'Page/Project_Info.html', {'pj_name': pjName})
    return render(request, 'Page/Project_Info.html')


def add_project(request):  # 点击新增跳转出页面
    return render(request, 'Page/Add_Project.html')


def update_data_pj(request):  # 修改项目信息
    if request.method == "POST":
        id = request.POST.get('data_id')
        field = request.POST.get('field')
        value = request.POST.get('value')
        if field == 'pj_id':
            models.Project_Data.objects.filter(id=id).update(pj_id=value)
        elif field == 'pj_name':
            models.Project_Data.objects.filter(id=id).update(pj_name=value)
        elif field == 'pj_pname':
            models.Project_Data.objects.filter(id=id).update(pj_pname=value)
        elif field == 'pj_tname':
            models.Project_Data.objects.filter(id=id).update(pj_tname=value)
        elif field == 'pj_pn':
            models.Project_Data.objects.filter(id=id).update(pj_pn=value)
        else:
            models.Project_Data.objects.filter(id=id).update(pj_state=value)
        return render(request, 'Page/Interface_List.html')
